package com.xinlianshiye.im.response

import com.fasterxml.jackson.annotation.JsonFormat
import com.xinlianshiye.im.bean.FriendApplication
import java.util.*

class ApplyUserListView {
    var id // 好友申请表ID
            : Int? = null
    var status // 好友申请状态
            : Int? = null

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    var createtime // 创建好友申请表的创建时间
            : Date? = null
    var fromid // 用户ID
            : Int? = null
    var fromusername // 用户名称
            : String? = null
    var toid //申请人ID
            : Int? = null
    var toState: Boolean? = null
    var type //类型
            : Int? = null
    var postscript // 附言
            : String? = null
    var avatar // 头像
            : String? = null
    var state: Boolean? = null

    companion object {
        @JvmStatic
        fun init(userId: Int, friendApplication: FriendApplication): ApplyUserListView {
            val view = ApplyUserListView()
            view.id = friendApplication.id
            view.id = friendApplication.id
            view.state = friendApplication.haveRead
            view.status = friendApplication.applyState!!.ordinal
            view.toid = friendApplication.targetUserId
            view.toState = friendApplication.targetHaveRead
            view.createtime = Date.from(friendApplication.createTime)
            view.fromid = friendApplication.userId
            if (friendApplication.userId == userId) {
                view.avatar = friendApplication.targetUser!!.avatar
                view.fromusername = friendApplication.targetUser!!.username
                view.postscript = friendApplication.reply
            }
            if (view.toid == userId) {
                view.avatar = friendApplication.user!!.avatar
                view.fromusername = friendApplication.user!!.username
                view.postscript = friendApplication.postscript
            }
            return view
        }
    }
}